package com.imooc.SmartChargeStation.demo.controller;

import com.imooc.SmartChargeStation.demo.mqtt.PahoMode.service.impl.ClientServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName MqttPahoCtl
 * @Description mqtt(基于Eclipse Paho) web控制器
 * @author: puyunqing
 * @Date: 2025/9/25
 */
@RestController
public class MqttPahoCtl {

    @Resource
    private ClientServiceImpl clientService;


    //mqtt客户端发送消息
    @RequestMapping(value = "/paho/pub")
    public void pahoPub(
            @RequestParam("topic") String topic,
            @RequestParam("message") String message) {
        clientService.publish(topic, message);

        clientService.disconnct();
    }

    //mqtt客户端订阅主题
    @RequestMapping(value = "/paho/sub")
    public void pahoSub(@RequestParam String topic) {
        clientService.subScribe(topic);
        clientService.disconnct();
    }


}
